<?php
namespace app\apiadmin;

use app\BaseController as Base;
use think\facade\Cache;

/**
 * 应用控制器基础类
 */
abstract class BaseController extends Base
{
    /**
     * 应用名称
     */
    protected $appname;

    /**
     * 控制器名称
     */
    protected $controller;

    /**
     * 操作名称
     */
    protected $action;

    /**
     * 帐号ID
     */
    protected $admin_id;

    /**
     * 帐号信息
     */
    protected $admin_info;

    /**
     * 初始化
     *
     * @return void
     */
    protected function initialize()
    {
        parent::initialize();

        $this->appname    = "apiadmin";
        $this->controller = strtolower($this->request->controller());
        $this->action     = strtolower($this->request->action());

        // 除index控制器外，剩余所有页面都需要验证权限
        if ($this->controller != "index") {
            $auth = $this->request->param("auth", "", "trim");
            if (!empty($auth)) {
                $cache = Cache::get($auth);
                if (!empty($cache)) {
                    $array            = json_decode($cache, true);
                    $this->admin_id   = $array['id'];
                    $this->admin_info = $array;
                }
            }
        }
    }
}
